<script setup>

import {defineEmits, reactive, ref} from "vue";
import {message} from "ant-design-vue";
import {addObject} from "@/api/api";
// import {addObject} from "@/api/api";

const emit = defineEmits(['update'])


const open = ref(false);
const showDrawer = () => {
  open.value = true;
};
const valueOfType = ref('0')
const information = reactive({
  rno: '',
  type: 0
})

const commit = () => {
  if(information.rno === '' || valueOfType.value === '0'){
    message.warn("信息不能为空")
  }else{
    console.log(information);
    if(valueOfType.value === '1'){
      const data = {
        rno: information.rno,
        type: valueOfType.value,
        info: {
          ProjectName: '',
          ProjectNo: '',
          ProjectCode: '',
          ProjectLevel: '',
          TotalAmount: '',
          ApprovingDepartment: '',
          ProjectType: '',
          Duration:'',
          FundingRecords: '',
          Participants: '',
          PrincipalInvestigator: '',
          FinancialAccount: '',
          ClosingDate: '',
          ApprovalDocument: '',
          ClosureCertificate: '',
          ClosureReport: '',
          SubmissionDate: '',
          msg: ''
        }
      }
      console.log(data)
      addObject(data, "result").then(res => {
        if(res.data.status === 200){
          console.log(res.data.data)
          // location.reload()
          message.success("添加成功")
        }else{
          message.warn("添加失败")
        }
      })
    }
    if(valueOfType.value === '2'){
      const data = {
        rno: information.rno,
        type: valueOfType.value,
        info: {
          ProjectName: "",
          ContractNumber: "",
          TotalContractAmount: "",
          ClientOrganizationName: "",
          ProjectManager: "",
          ExecutionDirector: "",
          ProjectDuration: "",
          PaymentRecords:"",
          Participants: "",
          FinancialAccount: "",
          PaymentReceipts: "",
          ProjectClosureDate: "",
          ClosureCertificate: "",
          ClosureReport: "",
          SubmissionDate: "",
          msg: ''
        }
      }
      console.log(data)
      addObject(data, "result").then(res => {
        if(res.data.status === 200){
          console.log(res.data.data)
          // location.reload()
          message.success("添加成功")
          information.uno = ''
          information.pwd = ''
        }else{
          message.warn("添加失败")
        }
      })
    }
    if(valueOfType.value === '3'){
      const data = {
        rno: information.rno,
        type: valueOfType.value,
        info: {
          PaperTitle: "",
          Journal: "",
          IssueNumber: "",
          VolumeNumber: "",
          PageRange: "",
          IndexingLevel: "",
          AuthorList: "",
          FirstAuthor:"",
          CorrespondingAuthor: "",
          PublicationDate: "",
          ImpactFactor: "",
          PaperURL: "",
          SubmissionDate: "",
          msg: ''
        }
      }
      console.log(data)
      addObject(data, "result").then(res => {
        if(res.data.status === 200){
          console.log(res.data.data)
          // location.reload()
          message.success("添加成功")
          information.uno = ''
          information.pwd = ''
        }else{
          message.warn("添加失败")
        }
      })
    }

  }
}

</script>

<template>
  <a-button type="primary" @click="showDrawer">Add</a-button>
  <a-drawer
      v-model:open="open"
      class="custom-class"
      root-class-name="root-class-name"
      :root-style="{ color: 'blue' }"
      title="添加成果"
      placement="right"
      @close="emit('update')"
  >
    <div>
      <a-input style="margin-top: 2rem" v-model:value="information.rno" placeholder="Rno" />
     <a-select
          ref="select"
          v-model:value="valueOfType"
          style="width: 120px;margin-top: 2rem"
          @focus="focus"
      >
        <a-select-option value="1">横向课题</a-select-option>
        <a-select-option value="2">纵向课题</a-select-option>
        <a-select-option value="3">论文</a-select-option>
      </a-select>
    </div>
    <div style="margin-top: 2rem">
      <a-button type="primary" @click="commit">
        Submit
      </a-button>
    </div>
  </a-drawer>
</template>

<style scoped>

</style>